/**
 * @param {string} s
 * @param {string[]} words
 * @return {number}
 */
var numMatchingSubseq = function (s, words) {
  let res = 0

  function checkHas(str1, str2, k) {
    if (str2.length == 1) {
      return str1.indexOf(str2) !== -1
    }
    let index = str1.indexOf(str2[k])
    if (index != -1) {
      // if (k + 1 == str2.length) return true
      return checkHas(str1.slice(index+1), str2.slice(k+1), k )
    } else {
      return false
    }
  }
  for (let i = 0; i < words.length; i++) {
    if (checkHas(s, words[i], 0)) res++
  }
  return res
}
console.log(numMatchingSubseq('abcde', ['bb', 'acd', 'ace']))
